﻿<Window x:Class="FindReplace.FindReplaceDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:FindReplace"
        Title="查找和替换" Height="Auto" Width="277" ResizeMode="NoResize" SizeToContent="Height" KeyDown="Window_KeyDown" WindowStyle="ToolWindow" ShowInTaskbar="False" Topmost="False"
        FocusManager.IsFocusScope="True" WindowStartupLocation="CenterScreen" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="216">
    <Window.Resources>
        <my:SearchScopeToInt x:Key="searchScopeToInt"/>
        <BooleanToVisibilityConverter x:Key="boolToVis" />
        <my:BoolToInt x:Key="boolToInt"/>
        <DataTemplate x:Key="FindPageTemplate">
            <StackPanel>
                <TextBlock Margin="3">查找内容:</TextBlock>
                <ContentPresenter Content="{Binding }" />
                <StackPanel DataContext="{Binding DataContext}">
                    <TextBlock Margin="3" Visibility="{Binding ShowSearchIn,Converter={StaticResource boolToVis}}">查找范围:</TextBlock>
                    <ComboBox SelectedIndex="{Binding SearchIn, Mode=TwoWay,Converter={StaticResource searchScopeToInt}}" Margin="0 0 0 3" 
                              Visibility="{Binding ShowSearchIn,Converter={StaticResource boolToVis}}"
                              HorizontalAlignment="Stretch">
                    <ComboBoxItem>Current Document</ComboBoxItem>
                    <ComboBoxItem>All Documents</ComboBoxItem>
                </ComboBox>
                <Expander Header="查找选项" IsExpanded="False">
                    <StackPanel>
                        <CheckBox Margin="1" Name="chkCaseSensitive" IsChecked="{Binding CaseSensitive, Mode=TwoWay}">大小写匹配</CheckBox>
                        <CheckBox Margin="1" Name="chkSearchUp" IsChecked="{Binding SearchUp, Mode=TwoWay}">向上搜索</CheckBox>
                        <CheckBox Margin="1" Name="chkWholeWord" IsChecked="{Binding WholeWord, Mode=TwoWay}">全字匹配</CheckBox>
                        <CheckBox Margin="1" Name="chkRegex" IsChecked="{Binding UseRegEx, Mode=TwoWay}">正则匹配</CheckBox>
                        <CheckBox Margin="1" Name="chkWildcards" IsChecked="{Binding UseWildcards, Mode=TwoWay}">通配符</CheckBox>
                    </StackPanel>
                </Expander>
                </StackPanel>
            </StackPanel>
        </DataTemplate>        
    </Window.Resources>
    <Grid >
        <TabControl Name="tabMain" Height="Auto" BorderThickness="{Binding AllowReplace,  Converter={StaticResource boolToInt}}">
            <TabItem Header="快速查找" Name="tabFind"  ContentTemplate="{StaticResource FindPageTemplate}" Visibility="{Binding AllowReplace, Converter={StaticResource boolToVis}}">
                <StackPanel>
                    <TextBox Margin="3" Name="txtFind" AcceptsReturn="{Binding AcceptsReturn}" Text="{Binding TextToFind, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <Button Margin="3" IsDefault="True" HorizontalAlignment="Right" Width="88" Click="FindNextClick">查找下一个</Button>
                </StackPanel>
            </TabItem>
            <TabItem Header="快速替换" Name="tabReplace"  ContentTemplate="{StaticResource FindPageTemplate}" Visibility="{Binding AllowReplace, Converter={StaticResource boolToVis}}">
                <StackPanel>
                    <TextBox Margin="3" Name="txtFind2" AcceptsReturn="{Binding AcceptsReturn}" Text="{Binding TextToFind, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <TextBlock Margin="3">替换为:</TextBlock>
                    <TextBox Margin="3" Name="txtReplace" AcceptsReturn="{Binding AcceptsReturn}" Text="{Binding ReplacementText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Width="238">
                        <Button IsDefault="True" Margin="3" HorizontalAlignment="Right" Width="85" Click="FindNextClick">查找下一个</Button>
                        <Button Margin="3" HorizontalAlignment="Right" Width="65" Click="ReplaceClick">替换</Button>
                        <Button Margin="3" Width="71" Click="ReplaceAllClick">全部替换</Button>
                    </StackPanel>
                </StackPanel>
            </TabItem>
        </TabControl>
    </Grid>
</Window>
